


let obj1 = {
  age: 12,
  name: 'obj1'
}

let obj2 = {
  age: 13,
  name: 'obj2',
  bro: obj1
}

obj1.bro = obj2



const deepClone = (obj, hash = new WeakMap()) => {
  if (obj === null || typeof obj !== 'object') {
    return obj;
  }
  // if (hash.has(obj)) {
  //     return hash.get(obj);
  // }
  const objCopy = new obj.constructor
  // hash.set(obj, objCopy);
  Object.keys(obj).forEach(key => {
    objCopy[key] = deepClone(obj[key], hash);
  });

  return objCopy;
}

deepClone(obj2)